Calling javascript function with button and input

2019-09-16 03:31发布

I have a textbox and button in my page. I have several sets of the below for different purpose.

<input type="text" id="new" name="new" value="1" />
<input type="button" value="Edit" onclick="compute(edit(xxx));" />

Upon clicking on the button, I want to call a javascript function which will take in the value input in the textbox. Now I am wondering how am I suppose to retrieve the value from the input 'new' and pass it the 'xxx' as argument?

3条回答
Anthone
2楼-- · 2019-09-16 04:15

why you don't try this by Jquery it is to understand and easy to implement.

Jquery Documentation

$('input[type=button]').click(function(){
alert($('#new').val());// to get input text value
    $('#new').val('xxx');//to set input text value
});

your question Fiddle Here

查看更多
手持菜刀,她持情操
3楼-- · 2019-09-16 04:22
<input type="button" value="Edit" onClick="compute(edit(document.getElementById('new').value))" />

This is how you handle it there in the HTML.

Else you can write the same code in javaScript.

function edit()
{
     x = document.getElementById('new').value;
     //use this X.
}
查看更多
做个烂人
4楼-- · 2019-09-16 04:25

Try

<input type="button" value="Edit" onclick="compute(edit(document.getElementById('new').value));" />
查看更多
登录 后发表回答