iT邦幫忙

0

[筆記,表單,假資料]在空白表單中隨機填入亂數資料方便測試

舜~ 2019-06-14 16:43:381341 瀏覽

如標題,小弟在測試表單功能時會需要填入假資料來做測試,但欄位一多在填入就很麻煩討厭...

印象中以前chrome有相似的套件,現在的套件試了幾個不太會用XD
基本上都是固定上一次輸入的內容....

不過我需要的是只要填入空白欄位就好,有資料的要跳過,那自己也來弄一個~~

$('input[value=""]').each(function() {
    switch($(this).attr('type')) {
         case 'text':
             // 隨機數字英文
            $(this).val(Math.random().toString(Math.floor(Math.random()*34)+2).substring(2));
            break;
        case 'number':
            //隨機數字
            $(this).val(Math.floor(Math.random()*100));
            break;
        case 'email':
            //隨機信箱
            $(this).val(Math.random().toString(36).substring(2)+'@abc.com');
            break;
        default: break;
    } 
});

$('textarea').each(function() {
    if($(this).val() == ''){
        $(this).val(Math.random().toString(Math.floor(Math.random()*34)+2).substring(2));
    }
});

只要在該頁面F12 貼上執行就ok

--
2019/06/26 加入textarea


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

我要留言

立即登入留言