0

私のonkeypressでイベントを開催するためにこのJavaScriptを使用しています

function myFunction() {
   if (window.event || window.event.keyCode == 13) {   
      changeSource();
   } 
}

function changeSource(){
   document.getElementById("frame1").src="Log-In.aspx";
   window.alert("wow");
}

ここでonkeypressイベントを使用します

<input id= "Text1" placeholder="Search here..." type="text" onkeypress="myFunction()"/>

これは、イベントを変更したいiframeです。

<iframe id="frame1" width="100%" height="100%" frameborder="0" name="page" src="about:blank" ></iframe>

問題は、iframeのsrcを変更できないが、イベントがトリガーされていることです

4

1 に答える 1

0

属性値を変更するには、setAttribute を使用します。

document.getElementById("frame1").setAttribute('src',"Log-In.aspx");
于 2012-11-21T16:48:49.613 に答える