Javascript按钮点击问题 函数formSubmit() $('#newhtml').html('hello world'); 名字:

Javascript按钮点击问题 函数formSubmit() $('#newhtml').html('hello world'); 名字:,javascript,Javascript,使用上面的代码,我尝试单击按钮,在单击时执行formSubmit()函数,我的div newhtml不会更改为hello world 上面的代码有什么问题吗 谢谢 JavaScript函数的格式错误,请将它们括在括号中 <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></sc

使用上面的代码,我尝试单击按钮,在单击时执行formSubmit()函数,我的div newhtml不会更改为hello world

上面的代码有什么问题吗


谢谢

JavaScript函数的格式错误,请将它们括在括号中

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

<script>
function formSubmit()
$('#newhtml').html('hello world');
</script>

</head>
<body>
First name: <input type="text" id="fname" name="fname"><br>
<input type="button" onclick="formSubmit()" value="Search Data">
<div id="newhtml"></div>
</body>
</html>

此外,您不必包含两个不同版本的jQuery。

在函数中添加括号

function formSubmit(){
    $('#newhtml').html('hello world');
}
试试这个

function formSubmit() {
    $('#newhtml').html('hello world');
}

$(文档).ready(函数(){
$(“#输入”)。单击(函数(){
$('#newhtml').html('hello world');
})
});
HTML代码

 <script>
    $(document).ready(function(){

    $("#input").click(function(){
    $('#newhtml').html('hello world');

    })


    });

    </script>

名字:


函数formSubmit()
{
document.getElementById(“newhtml”).innerHTML=“hello world”;
}
`在这里输入代码`
名字:

@user1777711真是太神奇了……哈哈。括号更重要,你怎么会错过它……@user1777711这个答案是使用jqury你的函数不正确,它没有包含在括号中。为什么你的代码中有两个不同版本的jQuery。你为什么用jQuery打印Hello World??@user1021726:说得对。一个小错误会使你的项目陷入混乱。
<body>
First name: <input type="text" id="fname" name="fname"><br>
<input type="button" id="input" value="Search Data">
<div id="newhtml"></div>
</body>
 <head>

    <script>

      function formSubmit()
      {

          document.getElementById("newhtml").innerHTML="hello world";
      }
    </script>

</head>
<body>`enter code here`
    First name: <input type="text" id="fname" name="fname"><br>
   <input type="button" onclick="formSubmit()" value="Search Data">
  <div id="newhtml"></div>