<form method="get" action="{$pc_config['root']}" >
<input type='text' value="输入数字" />
<input type="button" onclick="pc_fav()" value=" 添加 " />
</form>
<script type="text/javascript">
function pc_fav(){
var pc_id = '这里要获取第一个input输入的值,请问怎么写';
</script>
function f(){
var mInput=window.getElementById('mid');
var v=mInput.getAttribute('value');
}
方式一:标签选择器
<script type="text/javascript">
function add() {
var input_arr = document.getElementsByTagName("input");
var input_first=input_arr[0];
var input_first_value =input_first.value;
console.log(input_first_value);
}
</script>
方式二:id选择器,或class选择器(推荐)
首先取出所有input
var inputArry = document.getElementsByTagName("input");
var inpValue = null;
for (var i = 0; i < inputArry.length; i++) {
if (i==0) {
inpValue = inputArry[i].value;
break;
}
}
jq写法:
$("form input:first-child").val()
function pc_fav(){
var pc_id = '$("form input:first-child").val();
alert(pc_id);
}
$("form input:nth-of-type(2)").click(function(){
pc_fav();
})
直接给附一个id
var pc_id = $("#txtnumber").val();//这里就是得到值了
var pc_id = document.get ElementsByTagName("input");
for(int i=0 ;i<pc_id.length; i++){
console.log(pc_id[i].value);
}
<br> function pc_fav(){<br> var pc_id = $("#number").val();<br> </script</p>
获取输入数字的值:
``
function pc_fav(){
var pc_id = $("input[type=text]").val()
}
http://blog.csdn.net/superit401/article/details/51762597
给input加个ID属性 用 $("#这里是input的ID,前面的符合不能少").val(), 直接可以获取到