前端常用知识

来源:互联网 发布:淘宝的全球购是真货吗 编辑:程序博客网 时间:2024/06/06 02:03

1、输入框中的值为默认不可改变

<input class="form-control" name="urlType" id="urlType" value="角色一" disabled

                       style="width:250px"/>



2、输入框有灰色提示输入,可输入

<input class="form-control" name="urlDescription" id="urlDescription" placeholder="分析测试过程"
                       style="width:250px"/>


3、window.open("/admin/addCache.do")浏览器打开另外一个窗口进行/admin/addCache.do这个URL访问


4、询问弹出窗口,点击确定后访问URL:reWarmCache.json

function reWarmCache() {
    if (confirm("确认刷新缓存?")) {
        $.ajax({
            url: "reWarmCache.json",// 跳转到 action
            success: function (data) {
                alert(data.message);
            },
            error: function () {
                alert("异常")
            }
        });
    }
}



5、

onclick函数动态传参

(1)参数为数值类型时:

var tmp = 123;
var strHTML = "<div onclick=func(" + tmp + ")>点击弹出数据及其类型</div>";
info.append(strHTML);
 
function func(tmp) {
    alert(typeof tmp + " " + tmp);
}

string 123

 

(2)参数为字符串类型时:

var tmp = "abc";
var strHTML = "<div onclick=func('" + tmp + "')>点击弹出数据及其类型</div>";
info.append(strHTML);
 
function func(tmp) {
    alert(typeof tmp + " " + tmp);
}

 打印出 string abc


(3)传两个及以上的参数时:

var tmp = "abcda";
var type = "xza";
//tmp参数和type参数之间不能有空格
var strHTML = "<div onclick=func('" + tmp + "','" + type + "')>点击弹出数据及其类型</div>";
info.append(strHTML);
 
function func(tmp, type) {
    alert(tmp + " " + type);
}

 打印出 abcda xza

 

(4)参数为数组时:

var tmp = ["abc","ddd","gg"];
var strHTML = "<div onclick=func('" + tmp + "')>点击弹出数据及其类型</div>";
info.append(strHTML);
 
function func(tmp) {
    alert(typeof tmp + " " + tmp);
}

 打印出  string abc,ddd,gg


6、输入框为只读,禁止编辑

<input class="form-control" type="text" readonly style="color:#000000">


7、 按Enter键进行查询

<input style="width:560px" type="text" class="form-control" id="paTestInput" placeholder="输入关键字">

对上面的输入框,按enter后,进行analysisProcessButtonclick()操作。

$('input#paTestInput').keypress(function (e) {
        if (e.which == 13) {
            analysisProcessButtonclick();
            return false;
        }
    });


8、重新加载页面

location.reload();


9、当前页面打开URL页面

window.location.href = url;

拓展:

parent.location.href="/url" 在父页面打开新页面
top.location.href="/url" 在顶层页面打开新页面



10、文字水平居中:text-align:center

      文字垂直居中:line-height:100px;


11、点击超链接要打开新的窗口只需加上  target="view_window",如果在原来窗口打开去掉target即可

例如<a href="www.suning.com" target="view_window">www.suning.com</a>

原创粉丝点击