2013-10-03 3 views
-2
<!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> 

위의 코드에서 formSubmit() 기능을 실행하는 버튼을 클릭하면 내 div newhtml이 hello world로 변경되지 않습니다.자바 스크립트 버튼 onclick 문제

위의 코드 문제 있나요 ..

감사합니다!

+1

기능이 올바르지 않습니다. 중괄호로 묶지 않습니다. –

+0

코드에 두 가지 버전의 jQuery가있는 이유는 무엇입니까? 그리고 왜 Hello World를 인쇄하기 위해 jQuery를 사용합니까 ??? – MarsOne

답변

1

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

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

    }) 


    }); 

    </script> 

HTML 코드

<body> 
First name: <input type="text" id="fname" name="fname"><br> 
<input type="button" id="input" value="Search Data"> 
<div id="newhtml"></div> 
</body> 
+0

@ user1777711이 답변은 jqury –

0

자바 스크립트 함수에 대한 귀하의 형식이 잘못 그들 괄호

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

에 포장, 당신은 jQuery를 서로 다른 두 가지 버전을 포함 할 필요가 없습니다.

1

시도 함수

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

놀라운. 나는 그 축복을 놓쳤다. 고마워! – user1777711

+0

@ user1777711 놀라운 .... .... 권자. 브래킷이 더 중요합니다 어떻게 그것을 놓칠 수 있습니다 ...... –

0

<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> 
를 괄호 추가

+0

@ user1021726 : rightly said used. 작은 실수로 인해 프로젝트가 엉망이 될 수 있습니다. – Javanator