本文介绍了你怎么能对齐单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写四个单选按钮的代码,希望它们居中对齐.html



Code that writes four radio buttons, would want them centre aligned on .html

public class ScanForWordsC {
    private static final Scanner INPUT = new Scanner(System.in);
    private static final String FILENAME = "F:/Android.html";

    public static void main(String[] args) throws FileNotFoundException {
        try (PrintStream output = new PrintStream(FILENAME)) {
            readFromUser(output);
        }
    }

    public static void readFromUser(PrintStream output) {
        String wordA = readLine("Word (a)");
        String wordB = readLine("Word (b)");
        String wordC = readLine("Word (c)");
        String wordD = readLine("Word (d)");
        String answer = readLine("Correct letter");

        output.println(radio("a", wordA, answer));
        output.println(radio("b", wordB, answer));
        output.println(radio("c", wordC, answer));
        output.println(radio("d", wordD, answer));
    }

    private static String readLine(String prompt) {
        System.out.print(prompt + ": ");
        return INPUT.nextLine();
    }

    private static String radio(String letter, String word, String answer) {
        String option = "(" + letter + ") " + word;
        String is = letter.equals(answer) ? "is" : "is not";

        return "<input type='radio' name='rbnNumber' value='You selected "
                + option + " which " + is +  " the correct answer' />"
                + option + "<br/>";
    }
}





我的尝试:



java类,集合和java文档



What I have tried:

java classes, collections and java docs

推荐答案

text-align:center





例如:



For example:

<!DOCTYPE html>
<html>
<body style="text-align:center">
    <input type='radio'>First</input><br/>
    <input type='radio'>Second</input><br/>
    <input type='radio'>Third</input><br/>
</body>
</html>


private static String radio(String letter, String word, String answer)
   {

       String option = "(" + letter + ") " + word;
       String is = letter.equals(answer) ? "is" : "is not";

       return "<html><table align = 'center'><tr><td>"
               + "<input type='radio' name='rbnNumber' value='You selected"
               + option + "which" + is + "the correct answer'/>"
               + option + "<br/>"
               + "</td></tr></html>";
   }


这篇关于你怎么能对齐单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:04
查看更多