admin管理员组文章数量:1406920
I'm trying to redirect my window in base a value of button but i can get work
this is my code
<!DOCTYPE html>
<html>
<body>
<p>Click the button to change the location of the first iframe element (index 0).</p>
<button class="godd" onclick="myFunction()">Try it</button>
<br>
<br>
<iframe src="http://localhost:8005/?xform=http://127.0.0.1:8080/output_path4fff"></iframe>
<iframe src="http://localhost:8005/?xform=http://127.0.0.1:8080/output_path4fff"></iframe>
<script src=".11.0.min.js">
$(document).ready(myFunction() {
var Vp = $('.godd').eq(0).text();
window.frames[0].top.location.href = 'http://' + Vp;
})
</script>
</body>
</html>
I'm trying to redirect my window in base a value of button but i can get work
this is my code
<!DOCTYPE html>
<html>
<body>
<p>Click the button to change the location of the first iframe element (index 0).</p>
<button class="godd" onclick="myFunction()">Try it</button>
<br>
<br>
<iframe src="http://localhost:8005/?xform=http://127.0.0.1:8080/output_path4fff"></iframe>
<iframe src="http://localhost:8005/?xform=http://127.0.0.1:8080/output_path4fff"></iframe>
<script src="http://code.jquery./jquery-1.11.0.min.js">
$(document).ready(myFunction() {
var Vp = $('.godd').eq(0).text();
window.frames[0].top.location.href = 'http://' + Vp;
})
</script>
</body>
</html>
please help
Share Improve this question edited Jan 23, 2017 at 5:44 Satpal 133k13 gold badges167 silver badges170 bronze badges asked Jan 23, 2017 at 5:19 user7412219user7412219 1441 gold badge3 silver badges11 bronze badges 1- checkout this stackoverflow./questions/15171008/… – ricky Commented Jan 23, 2017 at 5:30
3 Answers
Reset to default 3Jquery Code should be like following:
function myFunction() { /* myfunction declaration */
var Vp = $('.godd').eq(0).text();
window.frames[0].top.location.href = 'http://' + Vp ;
};
$(document).ready(function(){ /* DOM ready callback */
});
You should define your function outside DOM ready. Read $(document).ready
Your script tag should be like this:
<script src="http://code.jquery./jquery-1.11.0.min.js"></script>
<script>
//Jquery Code
</script>
please call function on page ready below code. please check it once:
<script>
function myFunction(){
var Vp = $('.godd').eq(0).text();
window.frames[0].top.location.href = 'http://' + Vp ;
}
$(document).ready(function(){
myFunction();
});
</script>
script
elements can have a src
attribute or content, but not both. If they have both, the content is ignored (the content is considered "script documentation," not code).
Use another script block for your jQuery script
<script src="http://code.jquery./jquery-1.11.0.min.js"></script>
</script>
<script>
function myFunction() {
}
</script>
You need to define the function in Global scope as you accessing it using inline click handler.
function myFunction() {
var Vp = $('.godd').eq(0).text();
window.frames[0].top.location.href = 'http://' + Vp ;
};
$(document).ready(function(){
// DOM ready callback
});
However I would remend should use unobtrusive event handler instead of inline click handler.
$(document).ready(function(){
$('.godd').on('click', function() {
var Vp = $(this).text(); //Current element context
window.frames[0].top.location.href = 'http://' + Vp ;
});
});
HTML
<button class="godd">Try it</button>
本文标签: javascriptquotmessagequot quotUncaught ReferenceError myFunction is not definedquotStack Overflow
版权声明:本文标题:javascript - "message": "Uncaught ReferenceError: myFunction is not defined"? - Stack Overfl 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744977029a2635581.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论