1
我想通過動態創建的表單傳遞用戶名和密碼,但它沒有這樣做。這是JS。動態創建的表單只有在url包含特定的url詞幹時(location.pathname ... 3rd「if」語句)任何想法?這讓我瘋狂。當通過javascript動態創建時傳遞表單信息
function PostToAccountManagement() {
var userName = $('#Username').val();
var passWord = $('#Password').val();
if (userName == "")
$('#UsernameError').html('Please enter a valid username');
else
$('#UsernameError').html('');
if (passWord == "")
$('#PasswordError').html('Please enter a valid password');
else
$('#PasswordError').html('');
if (location.pathname.search(/\/info/i) == 0 ||
location.pathname.search(/\/blogs/i) == 0 ||
location.pathname.search(/\/groups/i) == 0 ||
location.pathname.search(/\/askquestion/i) == 0) {
$('<form id="Form1"> </form>').prependTo('body');
if (userName != "" && passWord != "") {
document.cookie = "ReturnUrl" + "=" + window.location.href;
$('#Form1').eq(0).attr('action', '/account/logon');
$('#Form1').eq(0).attr('method', 'post');
$('#Form1').submit();
}
}
if (userName != "" && passWord != "") {
document.cookie = "ReturnUrl" + "=" + window.location.href;
$('#Form1').eq(0).attr('action', '/account/logon');
$('#Form1').eq(0).attr('method', 'post');
$('#Form1').submit();
}
}
謝謝,這只是因爲包含這些網址的網頁沒有表單,因此我爲那些特定的網頁動態創建了它。我會看看我是否可以在其中放入一些輸入字段。謝謝 –