2016-12-04 75 views
0
  • 我想改變使用jQuery 按鈕被點擊,但它不爲我
  • 以下工作時的Selectpicker的標題的Selectpicker的標題是代碼

更改使用jQuery

<html> 
 
    <head> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
 
<link rel="stylesheet" href="dist/css/bootstrap-select.css"> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
 
<script src="dist/js/bootstrap-select.js"></script> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
 
    <!-- Latest compiled and minified CSS --> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/css/bootstrap-select.min.css"> 
 

 
<!-- Latest compiled and minified JavaScript --> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/js/bootstrap-select.min.js"></script> 
 

 
<!-- (Optional) Latest compiled and minified JavaScript translation files --> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/js/i18n/defaults-*.min.js"></script> 
 

 
</head> 
 
<body> 
 
<script> 
 
    $("#chapter").attr("title", "Select Chapters"); 
 
</script> 
 
<div class="col-md-5"> 
 
    Select Chapter: 
 
\t <select class="form-control selectpicker" id="chapter" multiple data-live-search="true" data-live-search-placeholder="Search" title="Select Class First" data-actions-box="true"> \t \t \t 
 
\t </select> 
 
    <br /> 
 
    <button type="submit" class="btn btn-primary">Change</button> 
 
</div> 
 
</body> 
 
</html>

+0

儘量'prop',而不是'attr' – Viney

+0

我已經嘗試的道具,但它不工作。 –

+0

你想讓它改變提交按鈕點擊或頁面加載? –

回答

0

你可以改變你Jque RY代碼

$('#chapter').prop('title', 'New title'); 
$('#chapter').selectpicker('refresh'); 

function change(){ 
 
    
 
// $('#chapter').prop('title', 'New title'); 
 
    // $('#chapter').selectpicker('refresh'); 
 
    
 
    $('.bootstrap-select .filter-option').text('New title'); 
 
}
<html> 
 
    <head> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 
 
<link rel="stylesheet" href="dist/css/bootstrap-select.css"> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="dist/js/bootstrap-select.js"></script> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> 
 
    <!-- Latest compiled and minified CSS --> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/css/bootstrap-select.min.css"> 
 

 
<!-- Latest compiled and minified JavaScript --> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/js/bootstrap-select.min.js"></script> 
 

 
<!-- (Optional) Latest compiled and minified JavaScript translation files --> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/js/i18n/defaults-*.min.js"></script> 
 

 
</head> 
 
<body> 
 

 
<div class="col-md-5"> 
 
    Select Chapter: 
 
\t <select class="form-control selectpicker" id="chapter" multiple data-live-search="true" data-live-search-placeholder="Search" title="Select Class First" data-actions-box="true"> \t \t \t 
 
\t </select> 
 
    <br /> 
 
    <button onclick='change()' type="submit" class="btn btn-primary">Change</button> 
 
</div> 
 
</body> 
 
</html>

+0

感謝@Hudhaifa Yoosuf爲您的答覆,但它不工作 –

+0

請現在檢查,我已更新它更改按鈕點擊..我已經測試,它的工作原理 –