gpt4 book ai didi

javascript - 在选中单击时禁用和启用文本框

转载 作者:行者123 更新时间:2023-12-02 20:23:08 26 4
gpt4 key购买 nike

如果选中复选框,则应启用文本框,否则应禁用文本框。

不知道为什么此代码不起作用?

<script type="text/javascript">
function toggleTB(what){
if(what.checked){document.test.from_address.disabled=1}
else{document.test.from_address.disabled=0}}
</script>

<% form_for(@test,:name => "test") do |f| %>
<table>
<tr>
<td class="right upcase none">
<%= f.label 'text_enabled', "Enable",:class => "capitalize none" %>
<%= f.check_box :text_enabled,:onclick => "toggleTB(this)" %>
</td>
</tr>

<tr>
<td class="right upcase none">
<%= f.label 'from_address', "From Address",:class => "capitalize none" %>
</td>
<td>
<%= f.text_field 'from_address', :maxlength => 16 %>
</td>
</tr>
</table>
<% end %>

有什么想法吗?

最佳答案

Try like this

<script type="text/javascript">
function toggleTB(what){
if(what.checked){document.getElementById('from_address').disabled=1}
else{document.getElementById('from_address').disabled=0}}
</script>

<input type="checkbox" name="toggle" onclick="toggleTB(this)"/>
<input type="input" id="from_address" />

关于javascript - 在选中单击时禁用和启用文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5258791/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com