2016-02-07 61 views
-1

我想設置客戶端將輸入到文本字段中的文本的樣式。該文本應顯示爲我的HTML格式。我有3個switch語句。 我如何使用跨度來設計它。使用跨度jquery設計字符串

var text = myProjectpage.model.currentChoices.TextLine1Text; 

switch(myProjectpage.model.currentChoices.TextLine1Text.length) { 
    case 1: 
     layer_InHTML= text; // allows what the user types to show in my html 
     //one letter should be big. 
     break; 
    case 2: 
     layer_InHTML = "<span ='font-size:2.5em;'>text.charAt(0)</span>"+charAt(1) 
     // this does not work. How can I improve this? 
     //two letters should be big 
    case 3: 
     //three letters should be big. 
     break; 
+0

你可以請創建一個jsfiddle嗎? – brk

回答

0

如果你想大的信函,除了最後一個(從案例2進去你的switch語句),您可以只使用下面的代碼沒有任何switch語句:

var text = myProjectpage.model.currentChoices.TextLine1Text; 
layer_InHTML = "<span style='font-size:2.5em;'>"+text.substr(0,text.length-1)+"</span>"+text.substr(text.length-1); 

檢查演示 - Fiddle

+0

我解決了你的問題嗎? –