Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将文本插入iframe表单字段&;提交_Javascript_Forms_Iframe_Insert_Submit - Fatal编程技术网

Javascript 将文本插入iframe表单字段&;提交

Javascript 将文本插入iframe表单字段&;提交,javascript,forms,iframe,insert,submit,Javascript,Forms,Iframe,Insert,Submit,好的,我们在配置文件上有一个星级系统,它作为iframe嵌入,不安全,因为它暴露了数据库表等等,但这就要来了。现在,我们希望在iframe中的表单中,从1-5向隐藏字段插入评级值,并自动提交。我们如何才能做到这一点?一些在线示例不起作用 iframe内部: <form action="submit_rating.php" method="POST"> <input type="text" name="1" id="rate1" maxlength="1"> <

好的,我们在配置文件上有一个星级系统,它作为iframe嵌入,不安全,因为它暴露了数据库表等等,但这就要来了。现在,我们希望在iframe中的表单中,从1-5向隐藏字段插入评级值,并自动提交。我们如何才能做到这一点?一些在线示例不起作用

iframe内部:

<form action="submit_rating.php" method="POST">
  <input type="text" name="1" id="rate1" maxlength="1">
  <input type="text" name="2" id="rate2" maxlength="1">
  <input type="text" name="3" id="rate3" maxlength="1">
  <input type="text" name="4" id="rate4" maxlength="1">
  <input type="text" name="5" id="rate5" maxlength="1">
  <input type="submit" value="Rate" style="display:none;" />
</form>

iframe:

<iframe src="http://domain.com/submit_rating.php" frameborder="0" scrolling="no" height="10" width="25" name="frame"></iframe>

评级链接:

<a href="howtoinsert?">1</a>
<a href="howtoinsert?">2</a>
<a href="howtoinsert?">3</a>
<a href="howtoinsert?">4</a>
<a href="howtoinsert?">5</a>

多谢各位。正如我所说,所有其他示例都是垃圾,不起作用。

您可以这样做(使用jquery):

评级网站:

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script>
      function setRating(rating) {
        var frame = $('iframe')[0].contentWindow.document;
        $(frame).find('#rate'+rating).val('1');
        $(frame).find('form').submit();
      }
    </script>
  </head>
  <body>
    <iframe src="frame.html" frameborder="0" scrolling="no" height="10" width="25" name="frame"></iframe>
    <a href="javascript:setRating(1)">1</a>
    <a href="javascript:setRating(2)">2</a>
    <a href="javascript:setRating(3)">3</a>
    <a href="javascript:setRating(4)">4</a>
    <a href="javascript:setRating(5)">5</a>
  </body>
</html>

功能设置额定值(额定值){
var frame=$('iframe')[0].contentWindow.document;
$(frame.find(“#rate”+rating.val('1');
$(frame.find('form').submit();
}
框架内容:

<!DOCTYPE html>
<html>
  <head>
    <title></title>
  </head>
  <body>
    <form action="submit_rating.php" method="POST">
      <input type="text" name="1" id="rate1" maxlength="1">
      <input type="text" name="2" id="rate2" maxlength="1">
      <input type="text" name="3" id="rate3" maxlength="1">
      <input type="text" name="4" id="rate4" maxlength="1">
      <input type="text" name="5" id="rate5" maxlength="1">
      <input type="submit" value="Rate" style="display:none;" />
    </form>
  </body>
</html>

但更好的方法是使用ajax:

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script>
      function setRating(rating) {
        $.post('submit_rating.php', {
          rating: rating
        });
      }
    </script>
  </head>
  <body>
    <a href="javascript:setRating(1)">1</a>
    <a href="javascript:setRating(2)">2</a>
    <a href="javascript:setRating(3)">3</a>
    <a href="javascript:setRating(4)">4</a>
    <a href="javascript:setRating(5)">5</a>
  </body>
</html>

功能设置额定值(额定值){
$.post('submit_rating.php'{
评级:评级
});
}
您可以这样做(使用jquery):

评级网站:

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script>
      function setRating(rating) {
        var frame = $('iframe')[0].contentWindow.document;
        $(frame).find('#rate'+rating).val('1');
        $(frame).find('form').submit();
      }
    </script>
  </head>
  <body>
    <iframe src="frame.html" frameborder="0" scrolling="no" height="10" width="25" name="frame"></iframe>
    <a href="javascript:setRating(1)">1</a>
    <a href="javascript:setRating(2)">2</a>
    <a href="javascript:setRating(3)">3</a>
    <a href="javascript:setRating(4)">4</a>
    <a href="javascript:setRating(5)">5</a>
  </body>
</html>

功能设置额定值(额定值){
var frame=$('iframe')[0].contentWindow.document;
$(frame.find(“#rate”+rating.val('1');
$(frame.find('form').submit();
}
框架内容:

<!DOCTYPE html>
<html>
  <head>
    <title></title>
  </head>
  <body>
    <form action="submit_rating.php" method="POST">
      <input type="text" name="1" id="rate1" maxlength="1">
      <input type="text" name="2" id="rate2" maxlength="1">
      <input type="text" name="3" id="rate3" maxlength="1">
      <input type="text" name="4" id="rate4" maxlength="1">
      <input type="text" name="5" id="rate5" maxlength="1">
      <input type="submit" value="Rate" style="display:none;" />
    </form>
  </body>
</html>

但更好的方法是使用ajax:

<!DOCTYPE html>
<html>
  <head>
    <title></title>
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script>
      function setRating(rating) {
        $.post('submit_rating.php', {
          rating: rating
        });
      }
    </script>
  </head>
  <body>
    <a href="javascript:setRating(1)">1</a>
    <a href="javascript:setRating(2)">2</a>
    <a href="javascript:setRating(3)">3</a>
    <a href="javascript:setRating(4)">4</a>
    <a href="javascript:setRating(5)">5</a>
  </body>
</html>

功能设置额定值(额定值){
$.post('submit_rating.php'{
评级:评级
});
}

现在,如果我只想插入一个自定义值,怎么做$(frame.find(“#about#me”+评级).val('1');通过示例自定义输入名称。谢谢如果我只想插入一个自定义值,怎么做$(frame.find(“#about#me”+评级).val('1');通过示例自定义输入名称。非常感谢。