提交如何在文本字段中显示跨度值

时间:2014-05-08 06:02:10

标签: javascript jquery html

如何使用javascript在文本字段中显示跨度值

我的代码就是这个

<span id="count">4</span>

我想在提交

的java脚本中显示4

4 个答案:

答案 0 :(得分:0)

在提交时尝试这样..

var spanText = document.getElementById('count').innerHTML;

document.getElementById('txtArear').value=spanText ;

答案 1 :(得分:0)

function SubmitForm(){
    var spanVal = $('span#count').text();
    $('textarea').val(spanVal);
} 

在提交

上试用此代码

答案 2 :(得分:0)

<强> HTML

<span id="count">4</span>
<input type="text" id="result"/>
<input type="button" id="submit"/>

<强> JQUERY

$('#submit').on('click', function(){
$('#result').val($('#count').html());

});

FIDDLE DEMO

答案 3 :(得分:0)

使用Javascript

<span id="count">4</span>
<input type="text" id='place_value'/>
<input type="button" value='Submit' onclick='place_val()' />

的Javascript

<script type="text/javascript">
function place_val()
{
    var span_value = document.getElementById("count").innerHTML;
    document.getElementById("place_value").value = span_value;
}
</script>

=========================

使用JQuery

<span id="count">4</span>
<input type="text" id='place_value'/>
<input type="button" value='Submit' id='submit' />

JQuery的

<script type="text/javascript">
$("#submit").on("click", function(){
    var span_value = $("#count").html();
    $("#place_value").val(span_value);
});
</script>