我在我的项目中使用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打印为
对象
发布于 2016-10-25 06:29:18
因此,您的表单加载了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>
https://stackoverflow.com/questions/40232659
复制相似问题