English 中文(简体)
• 如何从鲁比拉的见面助手中增加动态的 Java印法3?
原标题:How to add dynamic Javascript code from view helper in Ruby on Rails 3?

从一种观点出发审议以下法典:

<table>
  <tr>
    <th><%= f.label(:shop, "Shop:") %></th>
    <td><%= select_with_new_option(f, :shop, :name, :id) %></td>
  </tr>
  ...
</table>

我的助手方法在<条码>中界定。 它产生一个包含本案所有商店的选箱,此外还有“新商店”选择。

我愿补充一部 Java文法,显示:

<div>
  <label for="new_shop">New shop:</label>
  <input id="new_shop" name="new_shop" type="text" />
</div>

一旦选定了“新商店”方案。

是否可能从<条码>中产生这一 Java字码?

最佳回答

由于我看着你产生的法典,我只是这样说,但为了满足你们的需要,你不得不做精细的调整。 (这还假定你重新使用 j,必要时加以修改)。

假定你们的产出,就象:

table code and such

<select id="shop_select">
  <option value="new">New Shop</option>
  <!-- other options -->
</select>

somewhere on the page lives your div

<div id="new_shop_holder" style="display: none;">
  <label for="new_shop">New shop:</label>
  <input id="new_shop" name="new_shop" type="text" />
</div>

<script type="text/javascript">    
$(function(){
  var $new_shop_holder = $( #new_shop_holder );
  $( select#shop_select ).change(function(e) {
    if (this.value ==  new ) { $new_shop_holder.show(); }
    else { $new_shop_holder.hide(); }
  });
});
</script>
问题回答

你可以尝试

<%= select( shop , name , get_shop_name, {:include_blank => "Create"}, :onchange => "show_new_form();") %>

• 展示——新版是隐藏和展示贵新商店持有人的 j,或者你可以使用

<%= select( shop , name , get_shop_name, {:include_blank => "Select"}, :onchange => "new Ajax.Updater( options , action_url , {asynchronous:true, evalScripts:true, parameters:value})") %>

一、导 言

def action_url
render :update { |page| page.replace_html "new_shop_holder", :partial => add_new_shop } if value == ""
end

这将指只有选定一个商店才能进入新商店的部分。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签