簡體   English   中英

從用戶輸入輸出Textarea

[英]Output in Textarea from User Input

問題解決了

我剛剛開始學習JavaScript,在為我玩的游戲編寫快速工具時遇到了一個問題。 我希望用戶能夠通過HTML表單輸入一些內容,我希望JS腳本能夠獲取該輸入並將其轉換為SQL。

這是我的HTML:

 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>HabSQL - Online SQL Generator</title> <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'> <link href="css/styles.css" rel='stylesheet' type='text/css'> </head> <body> <header>Welcome to HabSQL v1.0! The Online Habbo SQL Generator!</header> <p>HabSQL is strictly for use with Habbo Furniture SQLs and Data. Please enter all necessary information accordingly.</p> <script src="scripts/habSQL.js"></script> <form action="javascript:void(habSQL())"> <fieldset> Furniture Name: <input id="furniName" type="text"> Furniture ID: <input id="furniID" type="number"><br> SWF File Name: <input id="fileName" type="text"> (Exclude .SWF)<br> Sprite ID: <input id="spriteID" type="number"> (We recommend that you use the same ID as Furniture ID). </fieldset> <fieldset> Furniture Type: <input id="furniType" type="radio" value="s" name="furniType">Floor <input id="furniType" type="radio" value="i" name="furniType">Wall <input id="furniType" type="radio" value="e" name="furniType">Effect<br> </fieldset> <fieldset> Furniture Width: <input id="furniWidth" type="number" class="dimensions"> Furniture Length: <input id="furniLength" type="number" class="dimensions"> Furniture Height: <input id="furniHeight" type="number" class="dimensions"><br> Can you stack furniture on it? <input id="canStack" type="radio" value="1" name="canStack">Yes <input id="canStack" type="radio" value="0" name="canStack">No<br> Can you sit on it? <input id="canSit" type="radio" value="1" name="canSit">Yes <input id="canSit" type="radio" value="0" name="canSit">No<br> Can you walk on/through it? <input id="canWalk" type="radio" value="1" name="canWalk">Yes <input id="canWalk" type="radio" value="0" name="canWalk">No<br> Can you recycle it? <input id="canRecycle" type="radio" value="1" name="canRecycle">Yes <input id="canRecycle" type="radio" value="0" name="canRecycle">No<br> Can you trade it? <input id="canTrade" type="radio" value="1" name="canTrade">Yes <input id="canTrade" type="radio" value="0" name="canTrade">No<br> Can you sell it on the Marketplace? <input id="canSell" type="radio" value="1" name="canSell">Yes <input id="canSell" type="radio" value="0" name="canSell">No<br> Can you give it to someone as a gift? <input id="canGive" type="radio" value="1" name="canGive">Yes <input id="canGive" type="radio" value="0" name="canGive">No<br> Can you stack it in the inventory? <input id="invStack" type="radio" value="1" name="invStack">Yes <input id="invStack" type="radio" value="0" name="invStack">No<br> </fieldset> <fieldset> Interaction Type:<br> <input id="intType" type="radio" value="default" name="intType">None<br> <input id="intType" type="radio" value="bed" name="intType">Bed<br> <input id="intType" type="radio" value="vendingmachine" name="intType">Vending Machine<br> <input id="intType" type="radio" value="trophy" name="intType">Trophy<br> <input id="intType" type="radio" value="gate" name="intType">Gate<br> <input id="intType" type="radio" value="onewaygate" name="intType">One Way Gate<br> <input id="intType" type="radio" value="dice" name="intType">Dice<br> <input id="intType" type="radio" value="teleport" name="intType">Teleporter<br> (More Interaction Types Coming in v2.0)<br> </fieldset> <fieldset> How many interactions does the furniture have? (ie a dice has 6 sides and a closed side, therefore 7 interactions.)<br> <input id="intCount" type="number"><br> If your furniture gives out an item, what is the item's ID? 0, if none. (View external_flash_texts.txt or external_flash_texts.xml for ID #'s.)<br> <input id="vendingID" type="number"><br> </fieldset> <input type="Submit" value="Generate!"> </form> Furniture SQL:<br> <textarea id="furniSQL" readonly="true" rows="10" cols="50"></textarea> </body> </html> 

這是我的JS:

 // HabSQL - Online Habbo SQL Generator // Developed by Thomas Yamakaitis - March 3, 2015 function habSQL() { var furniID = document.getElementById('furniID').value; var furniName = document.getElementById('furniName').value; var fileName = document.getElementById('fileName').value; var furniType = document.getElementById('furniType').value; var furniWidth = document.getElementById('furniWidth').value; var furniLength = document.getElementById('furniLength').value; var furniHeight = document.getElementById('furniHeight').value; var canStack = document.getElementById('canStack').value; var canSit = document.getElementById('canSit').value; var canWalk = document.getElementById('canWalk').value; var spriteID = document.getElementById('spriteID').value; var canRecycle = document.getElementById('canRecycle').value; var canTrade = document.getElementById('canTrade').value; var canSell = document.getElementById('canSell').value; var canGive = document.getElementById('canGive').value; var invStack = document.getElementById('invStack').value; var intType = document.getElementById('intType').value; var intCount = document.getElementById('intCount').value; var vendingID = document.getElementById('vendingID').value; var comma = ", "; var commaQuotes = "', '"; var quoteComma = "', "; var commaQuote = ", '"; document.getElementById('furniSQL').innerHTML = "INSERT INTO `furniture` (`id`, `public_name`, `item_name`, `type`, `width`, `length`, `stack_height`, `can_stack`, `can_sit`, `is_walkable`, `sprite_id`, `allow_recycle`, `allow_trade`, `allow_marketplace_sell`, `allow_gift`, `allow_inventory_stack`, `interaction_type`, `interaction_modes_count`, `vending_ids`, `is_arrow`, `foot_figure`, `height_adjustable`, `effectM`, `effectF`, `HeightOverride`) VALUES (" + furniId + commaQuote + furniName + commaQuotes + fileName + commaQuotes + furniType + quoteComma + furniWidth + comma + furniLength + comma + furniHeight + commaQuote + canStack + commaQuotes + canSit + commaQuotes + canWalk + quoteComma + spriteID + commaQuote + canRecycle + commaQuotes + canTrade + commaQuotes + canSell + commaQuotes + canGive + commaQuotes + invStack + commaQuotes + intType + quoteComma + intCount + comma + vendingID + ");"; } 

我似乎無法確切地指出我做錯了什么。 如果有人可以幫助我,我將不勝感激。

謝謝!

感謝這里的一些用戶! 解決方案是一個錯字,我相信它也是值而不是innerHTML。

Textareas是按價值修改的,而不是innerHTML

所以把它設置為

document.getElementById('furniSQL').value = "INSERT INTO `furniture` (`id`, `public_name`, `item_name`, `type`, `width`, `length`, `stack_height`, `can_stack`, `can_sit`, `is_walkable`, `sprite_id`, `allow_recycle`, `allow_trade`, `allow_marketplace_sell`, `allow_gift`, `allow_inventory_stack`, `interaction_type`, `interaction_modes_count`, `vending_ids`, `is_arrow`, `foot_figure`, `height_adjustable`, `effectM`, `effectF`, `HeightOverride`) VALUES (" + furniId + commaQuote + furniName + commaQuotes + fileName + commaQuotes + furniType + quoteComma + furniWidth + comma + furniLength + comma + furniHeight + commaQuote + canStack + commaQuotes + canSit + commaQuotes + canWalk + quoteComma + spriteID + commaQuote + canRecycle + commaQuotes + canTrade + commaQuotes + canSell + commaQuotes + canGive + commaQuotes + invStack + commaQuotes + intType + quoteComma + intCount + comma + vendingID + ");";

你應該好好去。

一個簡單的錯字:在最后一行用furniId而不是furniID

JavaScript區分大小寫,因此如果您以不同方式大寫變量名稱,則它是一個完全不同的變量,因此它不知道您的意思。

你的最后一個元素中有一個拼寫錯誤: furniID ,它是document.getElementById('furniSQL').value=拼寫為furniId

暫無
暫無

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

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