更改输入元素的值

时间:2010-04-27 14:42:22

标签: jquery

下面的代码花了我很多宝贵的时间,有人可以帮我吗?

<div id="i">
    <input id="Text1" type="text" value="hello" onClick="hello();"/>
</div>

<script>
    function hello() {
        var x = $("#i").html();
        var y = $(x).val();
        alert(y);
    }
</script>

在上面的情况下,“hello”这个词每次都会被提醒,如果我想提醒用户输入怎么办? 即如何更改输入字段的“值”属性???? 谢谢万亿

2 个答案:

答案 0 :(得分:1)

$("#Text1").click(
    function(){
        val = $(this).val(); // get the value of the input
        $(this).val('the new input value'); // set the value of the input
    }
);

这有意义吗?

答案 1 :(得分:0)

也许

function hello(){
    alert($("#Text1").val());//text that user has inputted
    $("#Text1").val('new text');//set new text for input element
}
相关问题