问题描述
我有一个函数,它将文本从txtdebt传递到debtsbox,
工作正常。但是,我想添加检查
debtsbox值的代码,如果用户输入的任何值包含字符串
" d"那么我想在页面
加载时禁用rblDebts。这部分不起作用(没有错误),我不知道为什么。
谢谢。
< script type =" text / javascript" ; language =" JavaScript">
<! - 开始
oldvalue ="" ;;
函数passText(传递值) {
if(passvalue!=""){
var totalvalue = passedvalue +" \ n" + oldvalue;
document.form1.debtsbox.value = totalvalue;
oldvalue = document.form1.debtsbox.value;
}
var searchfor =" d";
if(oldvalue.search(searchfor)-1){
document.form1.rblDebts.disabled = false;
}否则
document.form1.rblDebts.disabled = true;
}
//结束 - >
< / script>
债务ID:< input type =" ;文本"命名= QUOT; txtdebt" MAXLENGTH = QUOT; 5英寸/>
< input type =" button" value ="添加到列表" class =" buttonstyle2"
onClick =" passText(this.form.txtdebt.value);">
债务已添加到您的列表中:
< textarea cols =" 40"行= QUOT; 5英寸名称= QUOT; debtsbox" >< / textarea>
< input type =" radio" ID = QUOT; rblDebts" disabled =" true">
< / form>
一个单选按钮毫无意义。
nf
一个单选按钮毫无意义。
nf
啊,但在这种情况下,不是rblDebts代表一系列表单元素吗?
你不能禁用阵列。试试
document.form1.rblDebts [0] .disabled = false
看看会发生什么。
nf
I have a function which passes text from txtdebt to debtsbox which
works fine. However, I want to add code which examines the value of
debtsbox and if any of the values the user entered contain the string
"d" then I want to emable rblDebts which is disabled when the page
loads. This part is not working (no errors) and I''m not sure why.
Thanks.
<script type="text/javascript" language="JavaScript">
<!-- Begin
oldvalue = "";
function passText(passedvalue) {
if (passedvalue != "") {
var totalvalue = passedvalue+"\n"+oldvalue;
document.form1.debtsbox.value = totalvalue;
oldvalue = document.form1.debtsbox.value;
}
var searchfor = "d";
if (oldvalue.search(searchfor) -1) {
document.form1.rblDebts.disabled = false;
} else
document.form1.rblDebts.disabled = true;
}
// End -->
</script>
<form id="form1">
Debt ID: <input type="text" name="txtdebt" maxlength="5" />
<input type="button" value="Add to list" class="buttonstyle2"
onClick="passText(this.form.txtdebt.value);">
Debts added to your list:
<textarea cols="40" rows="5" name="debtsbox" ></textarea>
<input type="radio" id="rblDebts" disabled="true">
</form>
One radio button makes no sense.
http://www.w3.org/TR/1999/REC-html40...rms.html#radio
nf
One radio button makes no sense.
http://www.w3.org/TR/1999/REC-html40...rms.html#radio
nf
Ah, but in that case, doesn''t rblDebts represent an array of form elements?
You can''t disable an array. Try
document.form1.rblDebts[0].disabled = false
and see what happens.
nf
这篇关于禁用表单元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!