2016-07-02 68 views
0

我的頁面上有一個選擇輸入。當我打印頁面時,選擇的所有選項都會被打印,而不是被選中的選項。我如何製作以便只打印選擇的選項?打印只從下拉列表中選擇的項目

<select class="form-control" id=myID onchange="update_status(this)"> 
     <option value="1" selected>Pending</option> 
     <option value="2">Under-Preparation</option> 
     <option value="3">Delivered</option> 
    </select> 
+0

你可以重新在的jsfiddle問題看起來罰款? –

+0

我用我的瀏覽器打印生成頁面的PDF,它看起來很好。 [見截圖](http://i.imgur.com/YWSWfG1.png) –

回答

0

這是可以做到如下─

function update_status(currentObj){ 
console.log(currentObj.options[currentObj.selectedIndex].value); 
} 

JS Fiddle

謝謝!

0

分叉你的代碼一點,它完美的作品。運行代碼片段進行演示。

function update_status(selected_option){ 
 
    console.log(selected_option.value); 
 
}
<select class="form-control" id=myID onchange="update_status(this)"> 
 
     <option value="s1" selected>Pending</option> 
 
     <option value="s2">Under-Preparation</option> 
 
     <option value="s3">Delivered</option> 
 
    </select>

0

添加THIS.VALUE代替這個,檢出片段。

function update_status(vm) { 
 
    console.log(vm); 
 
    }
<select class="form-control" id=myID onchange="update_status(this.value)"> 
 
     <option value="1" selected>Pending</option> 
 
     <option value="2">Under-Preparation</option> 
 
     <option value="3">Delivered</option> 
 
    </select>

相關問題