我几乎逐字逐句地复制Trent Richardson's impromptu example 10,但我无法让它发挥作用。出于某种原因,例子8和9对我来说不起作用。我猜它是显而易见的,但我无法弄明白。
头:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
<script src="jquery-impromptu.4.0.min.js" type="text/javascript"></script>
<!--<script src="common.js" type="text/javascript"></script>-->
<link rel="stylesheet" media="screen and (min-device-width: 1050px)" type="text/css" href="example.css">
<script type="text/javascript">
var txt = 'Try submitting an empty field:<br />
input type="text" id="alertName"
name = "myname" value="" />';
function mysubmitfunc(e,v,m,f){
an = m.children('#alertName');
if(f.alertName == ""){
an.css("border","solid #ff0000 1px");
return false;
}
return true;
}
</script>
体:
<button onclick="$.prompt(txt,{ submit: mysubmitfunc, buttons: { Ok:true } })" title="Example 10">Example 10</button>
答案 0 :(得分:2)
HTML:
<button id="example10">Example 10</button>
JavaScript的:
var text = 'Try submitting an empty field:<br><input type="text" id="alertName" name="myname" value="">';
$( '#example10' ).on( 'click', function () {
$.prompt( text, { submit: function ( e, val, $elem ) {
var input = $elem.children( '#alertName' )[0];
if ( input.value === '' ) {
$( input ).css({ border: '1px solid red' });
return false;
}
return true;
}, buttons: { Ok: true } });
});