I am trying to set my current iframe source with a variable that I created but it doesn't seem to work. I figured that my JavaScript syntax is wrong.

我正在尝试使用我创建的变量设置我当前的iframe源,但它似乎不起作用。我认为我的JavaScript语法错误。

My script is:

我的脚本是:

            <script type="text/javascript">
              $(document).ready(function(){
                var iframeAttributes = window.location.search; 
                var iframeForm = 'www.test.com/form.html';
                var iframeURL = iframeForm + iframeAttributes; 
                $('.testframe').attr('src', iframeURL);
              });
            </script>

My IFrame code is:

我的IFrame代码是:

            <iframe id="testframe" src="" width="600" height="586" frameBorder="0">></iframe>

3 个解决方案

#1


1

Your selector is wrong:

你的选择器错了:

$('.testframe').attr('src', iframeURL);

This tries to find elements with class testframe but you have set the ID in your HTML, not the class.

这会尝试使用类testframe查找元素,但您已在HTML中设置了ID,而不是类。

Use this to select the element with id testIframe:

使用它来选择id为testIframe的元素:

$('#testframe').attr('src', iframeURL);

更多相关文章

  1. 使用JavaScript多态在子类中创建唯一变量而不覆盖
  2. javascript入门笔记(1)——变量和计算
  3. 有没有办法检查两个数组是否具有相同的元素?
  4. 如何从json对象获取匹配元素的索引?
  5. 从单击使用属性作为变量进行AJAX调用。
  6. 为什么我不能删除数组的元素?
  7. jQuery插件:如何将元素引用传递给回调函数?
  8. 在JavaScript中访问PHP变量[重复]
  9. js的html元素的父节点,子节点

随机推荐

  1. c语言conio.h是什么意思
  2. c++怎么将字符串转数字
  3. c语言中==和=的区别
  4. const在c++中的意思
  5. static在c语言中是什么意思
  6. c语言switch case用法详解
  7. break和continue在跳出循环时的不同
  8. C语言sqrt函数的用法
  9. c语言num什么意思
  10. C语言的关键字有哪些?