没有改变在iframe内加载的输入按钮的背景颜色
Not changing the background color of input button loaded inside the iframe
我在我的项目中使用material-design
。我正在加载我的html
文件在iframe
。我的html
文件是
<form action="#" method="post" name="sign up for beta form">
<div class="header">
<p id="sampleTitle" contenteditable="true">Sign Up For Beta</p>
</div>
<div class="description">
<p contenteditable="true">Milkshake is almost ready. If you're interested in testing it out, then sign up below
to get exclusive access.</p>
</div>
<div class="input">
<input type="text" class="button" id="email" name="email" placeholder="NAME@EXAMPLE.COM">
<input type="submit" class="button" id="submit" value="SIGN UP">
</div>
</form>
我必须根据用户的选择改变按钮的背景颜色。为此,我使用"jquery.minicolors.js"并将我的脚本写为…
<script type="text/javascript">
// background button color
$(document.body).on('change', '#hue-demo-btn-bg', function () {
var val = $(this).val();
console.log($(document).find('#submit'));
$(document).find('#submit').attr('style', 'background-color: ' + val + ' !important');
});
</script>
它不改变按钮的background color
也打印空的object
作为
对象[]
因此,您的表单加载了iframe
,您必须使用jQuery('#PLACE_IFRAME_ID').contents()
选择器来获取iframe内容。
和更改提交按钮的背景颜色请使用下面的代码。
jQuery('#PLACE_IFRAME_ID').contents().find('#submit').attr('style', 'background-color: ' + val + ' !important');
注意:在#PLACE_IFRAME_ID
的位置放置您的iframe's
id在选择器。
请完成工作演示:
// background button color
$(document.body).on('change', '#hue-demo-btn-bg', function () {
var val = $(this).val();
jQuery('#IframeID').contents().find('#submit').attr('style', 'background-color: ' + val + ' !important');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ifrmae id="IframeID">
<form action="#" method="post" name="sign up for beta form">
<div class="header">
<p id="sampleTitle" contenteditable="true">Sign Up For Beta</p>
</div>
<div class="description">
<p contenteditable="true">Milkshake is almost ready. If you're interested in testing it out, then sign up below
to get exclusive access.</p>
</div>
<div class="input">
<input type="text" class="button" id="email" name="email" placeholder="NAME@EXAMPLE.COM">
<input type="submit" class="button" id="submit" value="SIGN UP">
</div>
</form>
</iframe>
<select id="hue-demo-btn-bg">
<option value="">select</option>
<option value="red">red</option>
<option value="orange">Orange</option>
<option value="blue">Blue</option>
</select>
相关文章:
- 更改输入按钮's onClick参数
- 通过提示中的循环触发iFrame中的输入按钮(JavaScript)
- 将 CSS 应用于禁用的输入按钮
- 仅对一个输入按钮禁用应用
- 不显示为表单元素的图像输入按钮的动态创建和appendChild
- 如果未选中复选框,则禁用引导输入按钮
- 如果从文件输入按钮调用 .ajaxSubmit() 时,它是必需的表单
- JavaScript - 输入按钮隐藏 - 不起作用
- 输入按钮分隔显示按钮名称和值
- 单击列表中的引导输入按钮将禁用其他按钮
- javascript的事件监听器将下拉列表转换为输入按钮
- 表单验证和提交时提交文本&输入按钮上带有验证的图像
- JQuery-防止表单在输入按钮上提交,out防止按键敲击
- 如何使用javascript移除/隐藏、更改输入按钮的标题
- 检查输入按钮
- 每当我按下输入框内的键盘输入按钮(其中有文本)时,都会出现新的段落
- 每当在文本区域上输入按钮时,都会触发按钮
- 如果 e.keyCode 是“输入”按钮,并且元素包含其他文本,则验证条件
- 单击输入按钮时更新文本区域内容
- 如何显示输入按钮并关闭当前窗口