document.getElementById('content')无法获取输入框的值,获取的值为[object HTMLInputElement]。
用document.getElementById('content').value获取的值则为空,大家帮忙看看代码有哪些问题:
<div id="searchcontent">
<input type="text" name="wd" id="content" maxlength="100" class="s_ipt" autocomplete="off">
</div>
$(document).ready(function searchsub() {
jQuery('#searchcontent').append('<div><a href="http://www.baidu.com/s?wd='+ document.getElementById('content')+'" target="_blank">百度</a></div>');
});
------解决方案--------------------
你得重新绑定啊。
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function(){
jQuery('#searchcontent').append('<div><a href="http://www.baidu.com/s?wd='+ document.getElementById
('content').value+'" target="_blank">百度</a></div>');
$("#content").bind("change",function(){
$("a").attr("href","http://www.baidu.com/s?wd="+ document.getElementById('content').value+"");
});
});
</script>
</head>
<body>
<div id="searchcontent">
<input type="text" name="wd" id="content" maxlength="100" class="s_ipt" autocomplete="off">
</div>
</body>
</html>