I want to load html in specified situation. For example, signIn button that we can see on the website only load the page (html) if the id and password are correct.
<a class="btn btn-primary btn-lg" id="singIn" href="#" role="button">Sign In</a>
This is the signIn button in html.
$('#singIn').click(function() {
var userID = $('#userID').val();
var userPW = $('#userPW').val();
var tempID = "test";
var tempPW = "12345";
if (userID === tempID && userPW === tempPW) {
alert("userID : " + userID + ", userPW : " + userPW);
//TODO : load the local html file.
//var url = $(this).attr("href");
} else {
alert("userID : " + userID + ", userPW : " + userPW);
//TODO : load the other local html file or just alert.
}
});
This is the part (if/else statement) where I want to load my local html file as I mention first.
How can I do this? Please let me know. Thank you.
答案 0 :(得分:1)
尝试这样的事情,
$(this).attr('href', 'local url goes here');
答案 1 :(得分:0)
尝试使用带有隐藏按钮的验证功能进行实际提交:
$('[type="button"]').click(function() {
var valid = true;
$.each($('input'), function() {
valid = valid && $(this).val().length > 0;
})
if (valid) {
var location = 'http://www.rootdir.com/?user=' + $('input').get(0).value;
location += '&password=' + $('input').get(1).value;
alert(location);
// window.location.href = location; <-- uncomment to redirect to this url
} else {
alert('Please fill out all fields!');
}
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" placeholder="Enter Name" />
<input type="password" placeholder="Enter Password" />
<button type="button">Submit</button>
<button type="submit" id="realSubmit" style="display:none"></button>
&#13;