『壹』 js 如何把取得的值返回到 input value裡面,謝謝
varvalue;//js取得的值
document.getElementBy("inputId").value=value;//原生
$("#inputId").val(value);//jquery
『貳』 js如何獲取當前input的value值
在頁面中我們最常見的頁面元素就是input了,但是我們如何用javaScript得到網頁input中輸入的value值呢,其實很簡單,方法也不止一種,據我總結比較常用的就是下面的兩種方法,閑話不多說了,下面那就來看看我說的方法吧:
方法一、
Java代碼
<html>
<head>
<scriptlanguage="javascript">
functionprint(){
vara=myform.name.value;
alert(a);
}
</script>
</head>
<body>
<formname="myform">
<inputtype="text"name="name"id="nn"/>
<inputtype="button"name="button"value="獲取"onclick="print()"/>
</form>
</body>
</html>
這是獲取網頁input值的方法之一,給from一個名字然後在JavaScript的地方就可以用form的名字來調用form表單里input元素的value屬性可以得到值,並把值賦給a,最後用JavaScript的alert()列印方法列印出來。
方法二、
JS代碼
<html>
<head>
<scriptlanguage="javascript">
functionprint(){
vara=document.getElementById("nn").value;
alert(a);
}
</script>
</head>
<body>
<form>
<inputtype="text"name="name"id="nn"/>
<inputtype="button"name="button"value="獲取"onclick="print()"/>
</form>
</body>
</html>
『叄』 用js怎麼獲得<s:property />的value的值

<s:proprety>我也不動這個是什麼意思 就把h4的子元素有這個標簽和沒有這個標簽的都給寫了一下。
<html>
<head>
<meta charset="UTF-8"/>
<title></title>
</head>
<body>
<h4 ><s:proprety>就是</s:proprety></h4>
<p>我是不會出現在DIV中的</p>
<h4>這么</h4>
<h4 ><s:proprety>的</s:proprety>其實我不懂這是個什麼格式</h4>
<h4>簡單<s:proprety>我可是會出現的</s:proprety></h4>
<div id="div" style="width: 300px;height: 200px;border: 1px #ccc solid;">
<p style="background: red;">下面是h4標簽里的內容: </p >
</div>
<script type="text/javascript">
var div=document.getElementById("div");
var h4=document.getElementsByTagName("h4");
for (var i = 0; i < h4.length; i++) {
console.log(h4[i].childNodes[0])
if(h4[i].childNodes[0].nodeType==3){ //文本的節點屬性是3
div.innerHTML+=h4[i].innerText+"<br/>";
}else{
div.innerHTML+=h4[i].childNodes[0].innerText+"<br/>" }
}
</script>
</body>
</html>
『肆』 javascript 怎麼獲取選中的value值
可以給要獲取值的目標設置id,class,或者直接使用標簽名,樓下的方法
document.getElementById("id").value
或者document.getElementByClass("class").value
或者document.getElementByTabName("TabName").value
其中標簽的獲取,根據需要可能會用到選擇器相關的知識。
『伍』 JS獲取input text value里的值
你如果要用這個方法的話,那麼你的var total=0;這個就要設置成全局變數,也就是在function count(){}方法體之前就設置這個變數,那麼你的total就不會隨著每次點擊而刷新了。
『陸』 如何用js設置獲取value值
對於div來說復value屬性是自定製義屬性,因為div默認沒有value屬性。<br>獲取自定義屬性要使用getattribute方法。<br><br>function change(){<br> var u = document.getelementbyid("test").getattribute('value');<br> alert(u);<br>}
『柒』 JavaScript如何獲取LI的value值是多少
<form action="" method="get" class="search">
<fieldset>
<legend>搜索表單</legend>
<ul class="ul_search_tab">
<li value="0" class="on" onclick="SetSearchType(0)">商家</li>
<li value="1" onclick="SetSearchType(1)">產品</li>
</ul>
<div class="search_main">
<input name="keyword" type="text" class="ipt" />
<input name="" type="button" value="" class="btn" onclick="DoSearch();"/>
</div>
</fieldset>
</form>
在li標簽中加入onclick事件,以便把值賦給指定變數
『捌』 js怎麼獲取option的value
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<select id="sel">
<option value="1">4</option>
<option value="2">5</option>
<option value="3">6</option>
</select>
</body>
</html>
<script type="text/javascript">
var sel=document.getElementById("sel"); //獲取select
var op=sel.children; // 獲取所有的option
alert(op[0].value); //彈出option的第一個value值;
alert(op[1].value); //彈出option的第二個value值;
alert(op[3].value); //彈出option的第三個value值;
</script>
『玖』 js循環獲取頁面value值
因為一個文檔中的 name 屬性可能不唯一(如 HTML 表單中的單選按鈕通常具有相同的 name 屬性),所有 getElementsByName() 方法返回的是元素的數組,而不是一個元素。
varvalList=getElementsByName("name");
//獲取第一個的值。當然你也可以用循環
varval1=valList[0].value;
『拾』 js 中怎麼從input獲取輸入的value值
給input 一個ID屬性例如:<input type="text" id="name">
$("#name").val();
或者
document.getElementById("name").value