『壹』 js如何给<c:set>赋值
java的脚本可以给js赋值,如:
var str = '<%=str%>';
var arr = '${test}';
反之,js给java(标签)不能赋值,除非是有提交动作
『贰』 JS如何赋值给文本框
<script>
function ReadCookie(){
alert(getCookie("UserEmail").split(","));
}
function getCookie(objName){//获取指定名称的cookie的值
var arrStr = document.cookie.split("; ");
for(var i = 0;i < arrStr.length;i ++){
var temp = arrStr[i].split("=");
if(temp[0] == objName) return unescape(temp[1]);
}
}
var cookie_val = getCookie("UserEmail");
window.onload = ReadCookie();
</script>
<form name="addform" action="" method="get">
<input type="button" value="查看保存的COOKIES值" onclick="ReadCookie()">
<input type="text" id="txt1" value="" name="mail" onclick="ReadCookie()">
</form>
这样就能把cookie_val 的值赋给下面那个的文本框,直接显示出来
『叁』 js勾选复选框出来文本框
看看这样行不行
<p>
<input type="checkbox" name="checkbox" value="白色" onclick="showValue(this)"/>
白色
<input type="checkbox" name="checkbox2" value="黑色" onclick="showValue(this)"/>
黑色
<input type="checkbox" name="checkbox3" value="红色" onclick="showValue(this)"/>
红色
<input type="checkbox" name="checkbox4" value="蓝色" onclick="showValue(this)"/>
蓝色</p>
<p>如何才能勾选白色出来文本框并赋值呢如:</p>
<p>
<input id="textfield" name="textfield" type="text" value="">
</p>
</p>
<script>
function showValue(cb) {
if(cb.checked == true) {
document.getElementById("textfield").value = cb.value;
var items = document.getElementsByTagName("input");
for(var i = 0; i < items.length; i++) {
if(items[i].type == "checkbox" && items[i].value != cb.value) {
items[i].checked = false;
}
}
}
}
</script>
『肆』 用JS根据选择框的值来给输入框赋值
自己再按自己要求改改吧。
代码如下:
<!doctypehtml>
<html>
<head>
<metacharset="utf-8">
<title></title>
</head>
<body>
<selectid="s">
<optionx=1y=2>新租</option>
<optionx=3y=4>新买</option>
<optionx=5y=6>折旧</option>
</select>
<inputid="x"type=""name="">
<inputid="y"type=""name="">
</body>
<script>
document.getElementById('s').onchange=function(){
x=this.options[this.selectedIndex].getAttribute('x');
y=this.options[this.selectedIndex].getAttribute('y');
document.getElementById('x').value=x;
document.getElementById('y').value=y;
}
</script>
</html>