2013-09-28 39 views
0

裏面找了幾天,這個答案後接近,但仍然不會解決我的問題jQuery: How to assign a variable inside of .html指定變量的IFRAME

我試圖讓文本框的vaule到框架的SCR一部分。我明白,從上面的鏈接,JavaScript必須拉出變量或它將其視爲文本,但嘗試了幾天後無法讓它工作。在一個div的響應土地的頁面

<script> 
$(document).ready(function() { 
    $("#q").bind(
     "webkitspeechchange", 
     function(evt) { 
     $('.response').html(
      "<iframe width='625' height='250' border='0' src='/index.php?q=' + INPUT_HERE + ' /><br> voice search vaule:"+ $(this).val()) 
     .fadeIn(); 
}); 
}); 
</script> 

回答

0

這對工作對我來說:

<script> 
$(document).ready(function(){ 
    $('#q').on('webkitspeechchange', function(e) { 
     $('#response').html('<iframe width="625" height="250" border="1" src="/index.php?q=' + $(this).val() + '" /><br> Voice search value: ' + $(this).val()).fadeIn(); 
    }); 
}); 
</script> 

<input type="text" name="q" id="q" x-webkit-speech="x-webkit-speech"> 
<div id="response"></div> 

這裏是JS Fiddle

如果你想刪除周圍div可以調用$('#response').replaceWith(...代替$('#response').html(...,但請注意,由於#response已從DOM中刪除,所以連續搜索不再有效。

+0

爲我工作的輝煌!我只是將$(#響應)更改爲$(。response),並且所有工作都按預期工作 – JJohn