开发者

change the value of the input element

开发者 https://www.devze.com 2022-12-28 13:57 出处:网络
the following code is costing me a lot of precious time, can anybody help me on this?? <div id=\"i\">

the following code is costing me a lot of precious time, can anybody help me on this??

<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>

in the case above the word "hello" is alerted each and every time, what if i want to alert the user input??? i.e. how do i change the "value" attribute of the input field???? thanks a trillion


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

Does that make sense?


maybe

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

精彩评论

暂无评论...
验证码 换一张
取 消