簡體   English   中英

表單欄位(預設文字)+其他文字

[英]Form field (default text) + some more text

我有一個帶有默認文本的表單字段,但是我的用戶必須在此默認文本之后粘貼文件名。 我該如何實現?

/td><th width="200px">VideoLink</th><td><input type="text" id="VideoLink" name="VideoLink" value="<?php echo $video_rec['VideoLink']; ?>"></input></td>

$video_rec['VideoLink'] = "rtmp://test123.cloudfront.net/cfx/st/mp4:";

我的用戶必須將文件名粘貼到該表單字段中,但是在提交表單時,該字段應包含rtmp-url +文件名(test.mp4)Sample = rtmp://test123.cloudfront.net/cfx/st/mp4: TEST.mp4

我確實檢查了此解決方案。 如何在輸入字段中保留一些默認文本? ,但是當我右鍵單擊粘貼時,它將刪除默認文本。

您不應該相信您的用戶提供正確的輸入,而是讓他們按自己的意願粘貼,您可以使用注釋或標簽來指導他們。 請包括“ rtmp://”位,但最終您應該驗證輸入服務器端。

您可以嘗試以下方法:

$string = 'rtmp://test123.cloudfront.net/cfx/st/mp4:TEST.mp4';

//$string = 'test123.cloudfront.net/cfx/st/mp4:TEST.mp4';

// make sure to also strip any leading or trailing whitespace using trim()
// you can also process the input string even further before testing the protocol

if (!stripos($string)){
    $url = 'rtmp://' . trim($string);
}
else{
    $url = trim($string);
}

print $url;

像這樣:

HTML:

<input type="text" id="defaultLink" name="defaultLink" class="defaultLink" 
    value="rtmp://test123.cloudfront.net/cfx/st/mp4:" disabled />
<input type="text" id="videoLink" name="videoLink" />
<input type="hidden" id="completeLink" name="completeLink" />

<input type="button" onclick="appendLink();" value="Append" />

CSS:

.defaultLink {
    min-width: 235px;
    border: none;
    background-color: transparent;
}

JS:

function appendLink(){
    var defaultLink = document.getElementById('defaultLink').value;
    var videoLink = document.getElementById('videoLink').value;    
    var completeLink = defaultLink + videoLink;

    alert(completeLink);

    document.getElementById('completeLink').value = completeLink;

}

然后,您可以從completeLink請求屬性/參數獲取完整的URL。

演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM